import Vue from "vue"
import Vuex from "vuex"
import  cart from "./cart"
import product from "./product"

//引入 持久化 存储库
 import  createPersistedState  from "vuex-persistedstate"

Vue.use(Vuex)

let store = new Vuex.Store({
    state:{
        name:"李磊",
        age:18,
        nickName:"小磊",
        num:18,
        products:[]
    },
    getters: {
        reverseN(state){
            return state.nickName.split('').reverse().join('')
        }
    },
    mutations: {
        INCREASE(state,payload){
            state.num ++;
            console.log(payload)
        },
        REDUCE(state,payload){
            state.num --
            console.log(payload)
        }
    },
    actions: {
        FETCH_PRO(context,payload){
            console.log(context)
            fetch("http://chst.vip/data/index.json")
            .then(body=>body.json())
            .then((res)=>{
                console.log(res)
            })

        }
    },
    modules: {
        cart,
        product,
    },
    plugins:[
        createPersistedState({
            storage:window.localStorage,
            key:'nick',
            path:['nickname','product.products']
        })
    ]
        
       
    })

export default store